package cn.eyesea.cc;

import cn.eyesea.cc.config.DomainConfig;
import cn.eyesea.cc.config.GlobalConfig;
import cn.eyesea.cc.entity.DomainCommonConfig;
import cn.eyesea.cc.entity.DomainInfo;
import cn.eyesea.cc.entity.DomainRelation;
import cn.eyesea.cc.frame.context.CreateLogicalLayerCodeContext;
import cn.eyesea.cc.frame.processor.CreateLogicalLayerCodeProcessor;
import cn.eyesea.cc.frame.enums.LogicalLayerTypeEnum;
import cn.eyesea.cc.frame.processor.CreateLogicalTypeCodeProcessor;
import cn.eyesea.cc.frame.processor.impl.CreateLogicalLayerCodeProcessorDefaultImpl;
import cn.eyesea.cc.frame.processor.impl.CreateLogicalTypeCodeProcessorDefaultImpl;
import cn.eyesea.cc.util.ConfigUtil;
import cn.eyesea.cc.util.DBUtil;
import lombok.extern.slf4j.Slf4j;

import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * 黑箱执行流程
 *
 * @author wanghuilong
 * @version 1.0
 * @date 2021/7/12 3:12 下午
 */
@Slf4j
public class BlackBoxMain {

    static String globalConfigFile = "./globalConfig.properties";

    static String domainJsonFile = "./domain.json";

    static CreateLogicalTypeCodeProcessor createLogicalTypeCodeProcessor
            = new CreateLogicalTypeCodeProcessorDefaultImpl();

    static CreateLogicalLayerCodeProcessor createLogicalLayerCodeProcessor
            = new CreateLogicalLayerCodeProcessorDefaultImpl(createLogicalTypeCodeProcessor);


    public static void main(String[] args) throws UnsupportedEncodingException {
        GlobalConfig globalConfig = ConfigUtil.getGlobalConfig(globalConfigFile);
        log.info("globalConfig:{}", globalConfig);
        //准备配置
        ConfigUtil.configType(globalConfig);
        //查询数据库表信息
        DBUtil.setDbInfo(globalConfig);
        //读取domain.json配置
        DomainConfig domainConfig = ConfigUtil.getDomainConfig(domainJsonFile);

        List<DomainInfo> domains = domainConfig.getDomain();

        DomainCommonConfig domainCommonConfig = domainConfig.getDomainCommonConfig();

        List<DomainRelation> domainRelation = domainConfig.getRelation();

        for (LogicalLayerTypeEnum logicalLayerTypeEnum : LogicalLayerTypeEnum.getLogicalLayerTypeByIndex()) {
            for (int i = 0; i < domains.size(); i++) {
                CreateLogicalLayerCodeContext context = new CreateLogicalLayerCodeContext();
                context.setDomainInfo(domains.get(i));
                context.setLogicalLayer(logicalLayerTypeEnum);
                context.setDomainConfig(domainConfig);
                context.setGlobalConfig(globalConfig);
                createLogicalLayerCodeProcessor.process(context);
            }
        }


    }


}
